package cn.opopopo.design_pattern_learn.行为型.command;

import java.util.Stack;

// 智能遥控器（支持撤销）
public class RemoteControl {
    private Command currentCommand;
    private Stack<Command> commandHistory = new Stack<>(); // 用于撤销

    // 执行命令
    public void pressButton(Command command) {
        this.currentCommand = command;
        command.execute();
        commandHistory.push(command); // 记录历史
    }

    // 撤销
    public void pressUndo() {
        if (!commandHistory.isEmpty()) {
            Command lastCommand = commandHistory.pop();
            System.out.println("⏪ 执行撤销操作：");
            lastCommand.undo();
        } else {
            System.out.println("⏪ 无操作可撤销");
        }
    }
}